package hsmoto.core
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * 这个类主要是在自己的注册点放了个描点，还有就是添加和移除子元件，
	 * 描点的原因很简单，就是为了让获取的范围从注册点开始
	 * @author Zhang
	 * 
	 */	
	public class UISprite extends Sprite
	{
		public function UISprite()
		{
			this.addChild(new Bitmap(new BitmapData(1, 1, true, 0)));//添加描点
			
			this.addEventListener(Event.ADDED, add);
			this.addEventListener(Event.REMOVED, remove);
		}
		
		private function remove(event:Event):void
		{
			if((event.target as DisplayObject).parent == this)
				childRemove(event.target as DisplayObject);
		}
		
		private function add(event:Event):void
		{
			if((event.target as DisplayObject).parent == this)
				childAdd(event.target as DisplayObject);
		}
		/**
		 *有显示对象添加到自己 
		 */		
		protected function childAdd(child:DisplayObject):void
		{
			
		}
		/**
		 *有显示对象从自己移除
		 */		
		protected function childRemove(child:DisplayObject):void
		{
			
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject
		{
			return super.addChildAt(child, index + 1);
		}
		
		override public function getChildAt(index:int):DisplayObject
		{
			return super.getChildAt(index + 1);
		}
		
		override public function getChildIndex(child:DisplayObject):int
		{
			return super.getChildIndex(child) - 1;
		}
		
		override public function removeChildAt(index:int):DisplayObject
		{
			return super.removeChildAt(index + 1);
		}
		
		override public function setChildIndex(child:DisplayObject, index:int):void
		{
			super.setChildIndex(child, index + 1);
		}
		
		override public function swapChildrenAt(index1:int, index2:int):void
		{
			super.swapChildrenAt(index1 + 1, index2 + 1);
		}
		
		override public function get numChildren():int
		{
			return super.numChildren - 1;
		}
	}
}